unit Unit47; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Unit1,
  sqldb;

type

  { TForm47 }

  TForm47 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    ComboBox1: TComboBox;
    Edit1: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SQLQuery1: TSQLQuery;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow();
  private
    { private declarations }
  public
    codigo : string;
  end; 

var
  Form47: TForm47; 

implementation

{ TForm47 }

procedure TForm47.FormCreate(Sender: TObject);
begin
  SQLQuery1.Database := Form1.PQConnection1;
  SQLQuery1.Transaction := Form1.SQLTransaction1;
end;

procedure TForm47.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;
end;

procedure TForm47.Button1Click(Sender: TObject);
var
  QueryString : string;
  
begin
  QueryString := 'update funcionario set fnc_nombre = ''' + Edit1.Text + ''', fnc_descripcion = '''
    + ComboBox1.Text + ''' where fnc_cdg = ' + Edit3.Text;

  Form1.PQConnection1.ExecuteDirect('begin work;');
  Form1.PQConnection1.ExecuteDirect(QueryString);
  Form1.PQConnection1.ExecuteDirect('commit work;');
  
  ShowMessage('ACTUALIZACION EXITOSA');
  
  Close;
end;

procedure TForm47.FormShow();
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;
    
  SQLQuery1.SQL.Text := 'select fnc_nombre, fnc_descripcion from funcionario where fnc_cdg = '
    + codigo;
  
  SQLQuery1.Open;
  
  while not SQLQuery1.EOF do
  begin
    Edit1.Text := SQLQuery1.Fields[0].AsString;
    ComboBox1.Text := SQLQuery1.Fields[1].AsString;
    Edit3.Text := codigo;
    
    SQLQuery1.Next;
  end;
  
  SQLQuery1.Close;
end;

initialization
  {$I unit47.lrs}

end.

